%% Load GOOG.mat File and Monthly Returns
%Contains some monthly closing prices for Google's Stock
%Index 1    = 2004-09-01
%Index 110  = 2013-10-01
load('GOOG.mat'); 
%Calculates the monthly returns 
rtnsGOOG = (GOOG(2:end)-GOOG(1:end-1))./GOOG(1:end-1);

%Calculates the returns from 100 so that there aren't any negatives
rtnsFrom100 = rtnsGOOG + 1;

%% Calculate the Walk-Forward Predictions
%We'll take the geometric mean of the past 6 month periods
%except one will 'accidentally' peek at the period we're attempting
%to predict.

%User Selected Variables
calibrationMonths = 6;
walkForwardMonths = 1;

%Initialize Target Variables
meanNoPeek = zeros(1,1);
meanPeek   = zeros(1,1);
actualRtn  = zeros(1,1);
counter    = 1;

%This is the "walk-forward" 
for i=calibrationMonths:length(rtnsGOOG)-1
    start = (i-calibrationMonths)+1;
    meanNoPeek(counter,1) = geomean(rtnsFrom100(start:start+calibrationMonths-1))-1;
    meanPeek(counter,1)   = geomean(rtnsFrom100(start+1:start+calibrationMonths))-1;
    actualRtn(counter,1)  = rtnsGOOG(start+calibrationMonths);
    counter = counter+1;
end

%% Compare Predictions

cumulativeErrorNoPeek = cumsum(abs(meanNoPeek(:) - actualRtn(:)));
cumulativeErrorPeek   = cumsum(abs(meanPeek(:)-actualRtn(:)));


